package com.info3k.client.commands.address;

import com.google.gwt.maps.client.MapType;
import com.google.gwt.maps.client.MapWidget;
import com.google.gwt.maps.client.control.LargeMapControl3D;
import com.google.gwt.maps.client.control.MapTypeControl;
import com.google.gwt.maps.client.geom.LatLng;
import com.google.gwt.maps.client.overlay.Marker;
import com.google.gwt.maps.client.overlay.MarkerOptions;
import com.google.gwt.user.client.Command;
import com.info3k.client.Info3K;
import com.info3k.client.components.GlassDialogBox;
import com.info3k.client.domain.Address;


public class ShowAddressesCommand extends GlassDialogBox implements Command {

	private MapWidget map = new MapWidget(); 
	
	public ShowAddressesCommand(Address[] addresses){
		setText(Info3K.msgs.addresses());
		map.setSize("400px", "300px");
		map.addControl(new LargeMapControl3D());
		map.setCurrentMapType(MapType.getSatelliteMap());
		map.addControl(new MapTypeControl());
		
		for (Address address : addresses) {
			MarkerOptions options = MarkerOptions.newInstance();
			String s = address.getAddress();
			if(address.getHouseNumber()!=null)  
				s += " " + address.getHouseNumber();
			options.setTitle(s);
			Marker marker = new Marker(LatLng.newInstance(address.getLat(),address.getLon()), options);
			map.addOverlay(marker);			
			map.setCenter(LatLng.newInstance(address.getLat(),address.getLon()), 14);
		}
			
		content.add(map);
		
		footer.add(closeButton);
	}

	public void execute() {
		center();
	}
}